package com.example.parking.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.parking.dto.Result;
import com.example.parking.entity.Order;
import com.example.parking.mapper.OrderMapper;
import com.example.parking.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private IOrderService orderService;

    @Resource
    private OrderMapper orderMapper;


    /**
     * 预约停车功能
     * @param garageId 车位id
     * @param userId 用户id
     * @return
     */
    @PostMapping("/stop/{garageId}/{userId}")
    public Result stop(@PathVariable("garageId") Integer garageId, @PathVariable("userId") Integer userId){
        return orderService.stop(garageId, userId);
    }

    /**
     * 缴费结算功能
     * @param garageId
     * @param userId
     * @return
     */
    @PostMapping("/pay/{garageId}/{userId}")
    public Result pay(@PathVariable("garageId") Integer garageId, @PathVariable("userId") Integer userId){
        return orderService.pay(garageId, userId);
    }

    /**
     * 查询当前登录用户的订单信息
     * @return
     */
    @GetMapping("/getByLogin/{userId}")
    public Result getByLogin(@PathVariable Integer userId){
        List<Order> orderList = orderMapper.getByLogin(userId);
        return Result.successData(orderList);
    }
}
